<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" name="" id="diejia" placeholder="要叠加的次数">
  <input type="text" name="" id="num" placeholder="要叠加的数据">
  <button id="bian">变</button>
  <input type="text" name="" id="result1">
  <br>
  <input type="text" name="" id="val1" placeholder="数1">
  <input type="text" name="" id="val2" placeholder="数2">
  <button id="btn">最大公约数</button>
  <input type="text" name="" id="result2">
  <br>
  <input type="text" name="" id="shuju1" placeholder="数1">
  <input type="text" name="" id="shuju2" placeholder="数1">
  <button id="btn1">最小公倍数</button>
  <input type="text" name="" id="result3">
</body>
<script>
  // 打印100以内的所有偶数的和
  var num
  for (num = 1; num <= 100; num++) {
    if (num % 2 == 0) {
      document.write(num + ",")
    }
  }
  document.write("<br/>")
  // 求出1到1/100的和
  var num2
  var jian = 0
  var beijian = 0
  var total
  for (num2 = 1; num2 <= 100; num2++) {
    if (num2 % 2 == 0) {
      beijian = 1 / num2 + beijian
    } else if (num2 % 2 != 0) {
      jian = 1 / num2 + jian
    }
  }
  total = jian - beijian
  document.write(total + "<br/>")
  // 求1000-9999之间的4叶玫瑰数
  var num3
  for (num3 = 1000; num3 <= 9999; num3++) {
    var qian = parseInt(num3 / 1000)
    var bai = parseInt(num3 / 100) - qian * 10
    var shi = parseInt(num3 / 10) - (qian * 100 + bai * 10)
    var ge = num3 % 10
    if (num3 == qian * qian * qian * qian + bai * bai * bai * bai + shi * shi * shi * shi + ge * ge * ge * ge) {
      console.log(num3)
    }
  }
  // 山上有一口缸可以装50升水，现在有15升水。老和尚叫小和尚下山挑水，每次可以挑5升。
  // 问：小和尚要挑几次水才可以把水缸挑满？通过编程解决这个问题
  var num4 = 50
  var num5 = 15
  var num6
  var total2 = num4 - num5
  var cishu = 0
  for (num6 = 5; num6 <= total2; num6 = num6 + 5) {
    cishu++
  }
  document.write(cishu + "<br/>")
  // 打印三角形
  var num7
  var num8
  for (num7 = 0; num7 <= 10; num7++) {
    for (num8 = 1; num8 <= num7 + 1; num8++) {
      document.write("*")
    }
    document.write("<br/>")
  }
  // 打印水仙花数
  var num9
  for (num9 = 100; num9 <= 999; num9++) {
    var bai1 = parseInt(num9 / 100)
    var shi1 = parseInt(num9 / 10) - bai1 * 10
    var ge1 = num9 % 10
    if (num9 == bai1 * bai1 * bai1 + shi1 * shi1 * shi1 + ge1 * ge1 * ge1) {
      console.log(num9)
    }
  }
  // 求1 + 2！ + 3！ + 4！....+20!的值

  var sum = 0
  for (var i = 1; i <= 20; i++) {
    var result = 1
    for (var j = 1; j <= i; j++) {
      result *= j
    }
    console.log("第" + i + "个阶乘：" + result)
    sum += result
  }
  console.log(1 + "到" + i + "个阶乘总和：" + sum)

  // 求叠数之和（1-9）
  var bian = document.getElementById("bian");
  bian.onclick = function () {
    var total4 = 0
    var diejia = document.getElementById("diejia").value;
    var shu = document.getElementById("num").value;
    var result1 = document.getElementById("result1")
    var sum = 0
    for (var numbers = 1; numbers <= diejia; numbers++) {
      if (numbers == 1) {
        total4 += parseInt(shu)
      } else if (numbers >= 2) {
        total4 = total4 * 10 + 2
      }
      sum += parseInt(total4)
    }
    result1.value = sum
  }
  // 输入两个数,求两个数的最大公约数

  var btn = document.getElementById('btn')

  btn.onclick = function () {
    var val1 = parseInt(document.getElementById('val1').value)
    var val2 = parseInt(document.getElementById('val2').value)
    var result2 = document.getElementById("result2")
    if (val1 > val2) {
      for (var val3 = val2; val3 >= 1; val3--) {
        if (val2 % val3 == 0 && val1 % val3 == 0) {
          result2.value = val3
          break;
        } else {
          continue
        }
      }
    } else if (val1 < val2) {
      for (var val3 = val1; val3 >= 1; val3--) {
        if (val2 % val3 == 0 && val1 % val3 == 0) {
          result2.value = val3
          break;
        } else {
          continue
        }
      }
    } else {
      result2.value = val1
    }
  }
  // 输入两个数，求两个数的最小公倍数
  var btn1 = document.getElementById("btn1")
  btn1.onclick = function () {
    var shuju1 = parseInt(document.getElementById("shuju1").value)
    var shuju2 = parseInt(document.getElementById("shuju2").value)
    var result3 = document.getElementById("result3")
    if (shuju1 > shuju2) {
      for (var number1 = shuju1; number1 >= shuju1; number1++) {
        if (number1 % shuju1 == 0 && number1 % shuju2 == 0) {
          result3.value = number1
          break;
        } else {
          continue;
        }
      }
    } else if (shuju1 < shuju2) {
      for (var number1 = shuju2; number1 >= shuju2; number1++) {
        if (number1 % shuju1 == 0 && number1 % shuju2 == 0) {
          result3.value = number1
          break;
        } else {
          continue;
        }
      }
    } else {
      result3.value = shuju1
    }
  }

  // 回文数
  for (var huiwen = 10000; huiwen <= 99999; huiwen++) {
    var wan2 = parseInt(huiwen / 10000)
    var qian2 = parseInt(huiwen / 1000) - wan2 * 10
    var bai2 = parseInt(huiwen / 100) - wan2 * 100 - qian2 * 10
    var shi2 = parseInt(huiwen / 10) - wan2 * 1000 - qian2 * 100 - bai2 * 10
    var ge2 = parseInt(huiwen % 10)
    if (wan2 + 1 == qian2 && qian2 + 1 == bai2 && bai2 - 1 == shi2 && shi2 - 1 == ge2 && ge2 == wan2 && qian2 == shi2) {
      console.log("回文数：" + huiwen)
    } else {
      continue;
    }
  }
</script>



</html>